package cn.cheln.support.format;

import java.util.Date;

import android.content.Context;
import android.text.format.DateFormat;
import cn.cheln.support.log.Logs;
import cn.power.shine.R;

public class HourFormatter {
	public static String hourFormat;

	public static String showFormattedDate(Date dt, Context context) {
		if(dt==null){
			return null;
		}
		if(context == null)
		Logs.i("context = "+context);
		
		if (hourFormat == null) {
			hourFormat = android.provider.Settings.System.getString(
					context.getContentResolver(),
					android.provider.Settings.System.TIME_12_24);
		}
		String date = DateFormat.format("yyyy-MM-dd hh:mm", dt).toString();
		if (hourFormat == null || hourFormat.contains("12")) {
			String halfDay = context
					.getString(dt.getHours() < 13 ? R.string.morning
							: R.string.afternoon);
			String[] dates = date.split(" ");
			date = dates[0]+" "+halfDay+" "+(dates[1].startsWith("0")?dates[1].substring(1):dates[1]);
		}
		return date;
	}

}
